package dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import model.VilleTrain;

@Stateless
public class VilleTrainDaoImpl implements IVilleTrainDao {

	@PersistenceContext(unitName = "putravel")
	EntityManager em;

	@Override
	public VilleTrain findbyname(String nom) {
		Query req = em
				.createQuery("select v from  VilleTrain v where v.nom=:nom");
		req.setParameter("nom", nom);
		return (VilleTrain) req.getSingleResult();
	}

	@Override
	public VilleTrain findbycodeg(String codeg) {
		Query req = em
				.createQuery("select v from  VilleTrain v where v.codeG=:codeg");
		req.setParameter("codeg", codeg);
		return (VilleTrain) req.getSingleResult();
	}

	@Override
	public List<VilleTrain> findall() {
		Query req = em.createQuery("select v from  VilleTrain v ");
		return req.getResultList();
	}

}
